package net.maxwoods.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletContextAttributeEvent;
import javax.servlet.ServletContextAttributeListener;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

@WebListener
public class MyServlettListener implements ServletContextListener, ServletContextAttributeListener {

    private static final Logger logger = LoggerFactory.getLogger(MyServlettListener.class);

    @Override
    public void contextInitialized(ServletContextEvent event) {
        logger.warn("contextInitialized:{}", event);
    }

    @Override
    public void contextDestroyed(ServletContextEvent event) {
        logger.warn("contextDestroyed:{}", event);
    }

    @Override
    public void attributeAdded(ServletContextAttributeEvent event) {
        logger.warn("attributeAdded:{}={}", event.getName(), event.getValue());
    }

    @Override
    public void attributeRemoved(ServletContextAttributeEvent event) {
        logger.warn("attributeRemoved:{}={}", event.getName(), event.getValue());
    }

    @Override
    public void attributeReplaced(ServletContextAttributeEvent event) {
        logger.warn("attributeReplaced:{}", event.getName(), event.getValue());
    }
}
